package com.koocloud.electroplatemanage.controller;

import com.koocloud.electroplatemanage.common.pojo.ResponseTemplate;
import com.koocloud.electroplatemanage.pojo.WorkProcessVo;
import com.koocloud.electroplatemanage.service.ProductCompletedService;
import com.koocloud.electroplatemanage.service.WorkProcessService;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * @program: Information_platform
 * @description: 生产完成控制层
 * @author: xxc
 * @create: 2020-11-23 09:36
 */
@RestController
@RequestMapping("/productCompleted")
public class ProductCompletedController {
    static Logger log = Logger.getLogger("productCompleted");

    @Autowired
    ProductCompletedService productCompletedService;


    /**
     *@Description: 通过工单号查询一条数据
     *@Param: [workOrderNumber]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/23
     */
    @RequestMapping(value = "/selectByWorkOrderNumber", method = RequestMethod.POST, name = "通过工单号查询一条数据")
    public ResponseTemplate selectByWorkOrderNumber(String workOrderNumber) {
        //通过工单号查询一条数据
        return productCompletedService.selectByWorkOrderNumber(workOrderNumber);
    }

    /**
     *@Description: 查询所有记录 分页
     *@Param: [page, limit, idOrName]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/23
     */
    @RequestMapping(value = "/selectAllData", method = RequestMethod.POST, name = "全表查询")
    public ResponseTemplate selectAllData(String page, String limit, String idOrName) {
        //分页参数为空则赋值0
        if (!StringUtils.isNotEmpty(page)) {
            page = "0";
        }
        if (!StringUtils.isNotEmpty(limit)) {
            limit = "0";
        }
        //查询所有记录 分页
        return productCompletedService.selectAllData(page,limit,idOrName);
    }

    /**
     *@Description: 修改一条数据
     *@Param: [request, linkedHashMapList]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/23
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST, name = "修改一条数据")
    public ResponseTemplate update(HttpServletRequest request, @RequestBody LinkedHashMap data) {
        //获取修改人
        String userId = request.getHeader("userId");
        //修改一条记录
        return productCompletedService.update(data,userId);
    }
}
